<?php


namespace app\common\model\mysql;


class GoodsSku extends BaseModel
{

    //一对一关联查询
    public function goods()
    {
        return $this->hasOne(Goods::class, "id", "goods_id");
    }

    //goods_id 在sku表里查询sku数据
    public function getNormalByGoodsId($goodsId = 0)
    {
        $where = [
            "goods_id" => $goodsId,
            "status" => config("status.mysql.table_normal"),
        ];


        return $this->where($where)->select();

    }

    //库存减少
    public function incStock($id, $num)
    {
        return $this->where("id", $id)
            ->dec("stock", $num)
            ->update();
    }

}